<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width:200px;
            height:200px;
            border:solid 2px #999;
        }
    </style>
</head>
<body>
    <div></div>

    <script>
        const div = document.querySelector('div');
        //绑定事件
        div.onmouseover = function(){
            //
            const xhr = new XMLHttpRequest();
            //
            xhr.open("POST", "http://127.0.0.1/server");
            //设置请求体对应的头信息
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.setRequestHeader('auth', 'ajslkdfjalkwadfd');
            //post 请求参数要一般放置在『请求体』
            xhr.send('vip=9&wd=abc');
            //
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4){
                    if(xhr.status >= 200 && xhr.status < 300){
                        //将响应体的结果在 div 中呈现
                        div.innerHTML = xhr.responseText
                    }else{
                        alert('请求失败');
                    }
                }
            }
        }

    </script>
</body>
</html>